package cn.openread.demo.algorithm.p1;

import java.util.concurrent.CountDownLatch;

/**
 * 用途:一切为了业务
 *
 * @author simon
 * @date 2019-12-23 15:52
 * @see https://leetcode-cn.com/problems/print-in-order/solution/countdownlatchji-shu-qi-jie-ti-xiang-xi-si-lu-by-h/
 */
public class Foo {

    private CountDownLatch l1_2 = new CountDownLatch(1);
    private CountDownLatch l2_3 = new CountDownLatch(1);

    public Foo() {

    }

    public void first(Runnable printFirst) throws InterruptedException {
        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        l1_2.countDown();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        l1_2.await();
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        l2_3.countDown();

    }

    public void third(Runnable printThird) throws InterruptedException {
        l2_3.await();
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }

}
